import React from 'react';
import { Platform } from 'react-native';
import { createAppContainer, createStackNavigator, createBottomTabNavigator,createSwitchNavigator } from 'react-navigation';

import TabBarIcon from '../components/TabBarIcon';
import HomeScreen from '../screens/HomeScreen';
import InvitationScreen from '../screens/InvitationScreen';
import InviteScreen from '../screens/InviteScreen';
import MyScreen from '../screens/MyScreen';
import UserInfoScreen from '../screens/UserInfoScreen';
import ResetpswScreen from '../screens/ResetpswScreen';
import AboutScreen from '../screens/AboutScreen';
import RecordScreen from '../screens/RecordScreen';
import HatchScreen from '../screens/HatchScreen';
import HatchControlScreen from '../screens/HatchControlScreen';
import TakeMoneyScreen from '../screens/TakeMoneyScreen';
import LuckDrawScreen from '../screens/LuckDrawScreen';
import NoticeListScreen from '../screens/NoticeListScreen';
import NoticeDetailScreen from '../screens/NoticeDetailScreen';
import RechargeScreen from '../screens/RechargeScreen';
import ProfitRecordScreen from '../screens/ProfitRecordScreen';

const HomeStack = createStackNavigator({
  Home: { screen: HomeScreen },
  Record: RecordScreen,
  Take: {
    screen: TakeMoneyScreen
  },
  HatchControl: HatchControlScreen,
  Luck: LuckDrawScreen,
  Invite: InviteScreen,
  Recharge: RechargeScreen
},{
  initialRouteName: 'Home'
});

HomeStack.navigationOptions = ({ navigation }) =>{
  // console.warn(navigation)
  return{
      tabBarVisible: navigation.state.index > 0 ? false : true,
      tabBarLabel: '首页',
      tabBarIcon: ({ focused }) => (
        <TabBarIcon
          focused={focused}
          name='ios-home'
        />
      ),
  }
};

const HatchStack = createStackNavigator({
  Hatch: HatchScreen,
  HatchControl: HatchControlScreen,
  ProfitRecord: ProfitRecordScreen
});

HatchStack.navigationOptions =  ({ navigation }) =>{
  return{
    tabBarVisible: navigation.state.index > 0 ? false : true,
    tabBarLabel: '孵化',
    tabBarIcon: ({ focused }) => (
      <TabBarIcon
        focused={focused}
        name={Platform.OS === 'ios' ? 'ios-link' : 'md-link'}
      />
    ),
  }
};
const InvitationStack = createStackNavigator({
  Invitation: InvitationScreen,
  Invite: InviteScreen
});

InvitationStack.navigationOptions =  ({ navigation }) =>{
  return{
    tabBarVisible: navigation.state.index > 0 ? false : true,
    tabBarLabel: '邀请',
    tabBarIcon: ({ focused }) => (
      <TabBarIcon
        focused={focused}
        name={Platform.OS === 'ios' ? 'ios-person-add' : 'md-person-add'}
      />
    ),
  }
};

const MyStack = createStackNavigator({
  My: MyScreen,
  UserInfo: UserInfoScreen,
  Resetpsw: ResetpswScreen,
  About: AboutScreen,
  Notice: NoticeListScreen,
  NoticeDetail: NoticeDetailScreen
});

MyStack.navigationOptions = ({ navigation }) => {
  return{
    tabBarVisible: navigation.state.index > 0 ? false : true,
    tabBarLabel: '我的',
    tabBarIcon: ({ focused }) => (
      <TabBarIcon
        focused={focused}
        name={Platform.OS === 'ios' ? 'ios-person' : 'md-person'}
      />
    ),
  }
};
// export default {
//   HomeStack,
//   HatchStack,
//   InvitationStack,
//   MyStack,
// }

import LoginScreen from '../screens/LoginScreen';
import Register from '../screens/RegisterScreen';
import FindPasswordScreen from '../screens/FindPasswordScreen';
// const MainStack = createBottomTabNavigator({
//   homeStack: HomeStack
// })
const loginStack = createStackNavigator({ 
  Login: LoginScreen,
  Register: Register,
  FindPassword:FindPasswordScreen
},{
  initialRouteName:'Login'
})
const AppNavigator = createAppContainer(createSwitchNavigator({
  // You could add another route here for authentication.
  // Read more at https://reactnavigation.org/docs/en/auth-flow.html
  HomeStack : HomeStack,
  LoginNavigator: loginStack
}, {
  initialRouteName: 'HomeStack'
}));
export default AppNavigator;